//
//  MallsCollectionViewCell.m
//  CYWFrame
//
//  Created by Macx on 2017/8/31.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "MallsCollectionViewCell.h"
#import "Goods.h"

@implementation MallsCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = kWhiteColor;
	self.participatingView.hidden = YES;
    
    CGSize size1 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(12)];
    CGSize size2 = [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(10)];
    
    CGFloat width = (SCREEN_WIDTH-30)/2;
    
    self.pic.frame = CGRectMake(0, 0, width, width);
    self.pic.contentMode = UIViewContentModeScaleAspectFill;
	//self.pic.userInteractionEnabled = NO;
    self.pic.clipsToBounds = YES;
	
	CGRect frame1 = self.participatingView.frame;
	frame1.origin.y = self.pic.y+self.pic.height-self.participatingView.height;
	self.participatingView.frame = frame1;
	
    self.name.font = kUHSystemFontWithSize(12);
    self.name.numberOfLines = 2;
    self.name.frame = CGRectMake(2, self.pic.height+5, width-4, size1.height*2);
	
	
    self.money.font = kUHSystemFontWithSize(12);
    self.money.frame = CGRectMake(2, self.name.y+self.name.height+5, width/2-2, size1.height);
    
    self.nums.font = kUHSystemFontWithSize(10);
    self.nums.textAlignment = NSTextAlignmentRight;
    self.nums.frame = CGRectMake(width/2, self.money.height+self.money.y-size2.height, width/2-2, size2.height);
    
}

- (void)setModel:(Goods *)model {
    
    if (_model != model) {
        _model = model;
        
        [self.pic sd_setImageWithURL:[NSURL URLWithString:[model valueForKey:@"photo"][0]] placeholderImage:IMAGE(@"placeHolder")];
       
        self.name.text = [NSString stringWithFormat:@"%@\n", [model valueForKey:@"title"]];
        
        self.money.text = [NSString stringWithFormat:@"￥%.2lf", [[model valueForKey:@"price"] floatValue]/100];
        
        self.nums.text = [NSString stringWithFormat:@"已售%@件", [model valueForKey:@"sold_num"]];
		
		self.participatingView.hidden = YES;
    }
    
}

- (void)setModel2:(MallBuyTogetherModel *)model2
{
	if (_model2 != model2) {
		_model2 = model2;
		
		[self.pic sd_setImageWithURL:[NSURL URLWithString:[model2 valueForKey:@"photo"][0]] placeholderImage:IMAGE(@"placeHolder")];
		
		self.name.text = [NSString stringWithFormat:@"%@\n", [model2 valueForKey:@"title"]];
		
		self.money.text = [NSString stringWithFormat:@"￥%.2lf", [[model2 valueForKey:@"ecbuy_price"] floatValue]/100];
		
		self.nums.text = [NSString stringWithFormat:@"已拼%@单", [model2 valueForKey:@"ecbuy_total"]];
		self.participatingNum.text = [NSString stringWithFormat:@"%@人正在拼单", [model2 valueForKey:@"totalnum"]];
		self.participatingView.hidden = NO;
	}
}



@end
